package org.jrm.mechanics;

import java.util.Random;

public class ShadedCount {
	private Random gen = new Random();
	private long obfuscatedCount = 0;
	private int obfuscator;
	
	public int getCount() {
		obfuscatedCount -= obfuscator;
		int count = (int) obfuscatedCount;
		generateObfuscator();
		obfuscatedCount += obfuscator;
		return count;
	}
	
	public ShadedCount() {
		generateObfuscator();
		obfuscatedCount += obfuscator;
	}
	
	private void generateObfuscator() {
		obfuscator = gen.nextInt();
	}
	
	public void setCount(int count) throws InventoryItemsCountException {
		checkCount(count);
		obfuscatedCount -= obfuscator;
		obfuscatedCount = count;
		generateObfuscator();
		obfuscatedCount += obfuscator;
	}
	
	private void checkCount(int count) throws InventoryItemsCountException {
		if (count < 0) throw new InventoryItemsCountException(count);
	}
}
